package model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * This class represents a conference object
 * @author Rylie Nelson, Eric Preston
 */

public class Conference implements Serializable {
	
	/**
	 * Serial version ID
	 */
	private static final long serialVersionUID = -8066048735881681210L;

	/** Used to hold the name of the conference. */
	private String confName;
	
	/** ID number used for internal identification. */
	private int confID;
	
	/** Description used to diferentiate between conferences. */
	private String confDesc;
	
	/** Program chair of the conference. */
	private User progChair;
	
	/** Array of all the papers submitted to this conference. */
	private ArrayList<Paper> papers;
	
	/** All the sub PC's in this conference. */
	private List<User> SPC = new ArrayList<User>();
	
	/** All reviewers in this conference. */
	private List<User> reviewer = new ArrayList<User>();
	
	/** All authors in this conference. */
	private List<User> author = new ArrayList<User>();
	
	/**
	 * Constructor for the conference that has a program chair designated
	 * 
	 * @param input_name The name of the conference
	 * @param input_id the conference id
	 * @param input_desc the description of the conference
	 * @param pc the program chair for the conference
	 */
	
	public Conference(String input_name, int input_id, String input_desc, User pc) {
		confName = input_name;
		confID = input_id;
		confDesc = input_desc;
		progChair = pc;
		papers = new ArrayList<Paper>();
	}
	
	/**
	 * Constructor for a conference that does not have a designated program chair yet.
	 * 
	 * @param input_name the name of the conference
	 * @param input_id the conference id
	 * @param input_desc the description of the conference
	 */
	
	public Conference(String input_name, int input_id, String input_desc) {
		confName = input_name;
		confID = input_id;
		confDesc = input_desc;
		papers = new ArrayList<Paper>();
	}
	
	/**
	 * Returns a list of reviewers
	 * @return a list of reviewers
	 */
	public List<User> getReviewers() {
		List<User> reviewers = new ArrayList<User>();
		for(int i = 0; i < reviewer.size(); i++) {
			reviewers.add(reviewer.get(i));
		}
		return reviewers;
	}
	
	public List<User> getSPCs() {
		List<User> SPCs = new ArrayList<User>();
		for(int i = 0; i < SPC.size(); i++) {
			SPCs.add(SPC.get(i));
		}
		return SPCs;
	}
	
	/**
	 * Setter for the Program Chair
	 * @param user the Program Chair
	 */
	public void setPC(User user) {
		progChair = user;
	}
	
	/**
	 * Used to add a Sub Program Chair
	 * @param name The Sub Program Chair to be added
	 */
	public void addSPC(User name) {
		SPC.add(name);
	}
	
	/**
	 * Add a reviewer to this conference
	 * @param name The reviewer to be added
	 */
	public void addReviewer(User name) {
		reviewer.add(name);
	}
	
	/**
	 * Add an author to this conference
	 * @param name The author to be added
	 */
	public void addAuthor(User name) {
		author.add(name);
	}
	
	public int getID() {
		return confID;
	}
	
	/**
	 * Returns if this user is the program chair
	 * @param user the user to be checked
	 * @return true if the user is a program chair, false otherwise
	 */
	public boolean checkPC(User user) {
		boolean result = false;
		if (user.getName().equals(progChair.getName())) {
			result = true;
		}
		return result;
	}
	
	/**
	 * Returns if this user is the subprogram chair
	 * @param user the user to be checked
	 * @return true if the user is a subprogram chair, false otherwise
	 */
	public boolean checkSPC(User user) {
		boolean result = false;
		for (int i = 0; i < SPC.size(); i++) {
			if (user.getName().equals(SPC.get(i).getName())) {
				result = true;
				break;
			}
		}
		return result;
	}
	
	/**
	 * Returns if this user is a reviewer
	 * @param user the user to be checked
	 * @return true if the user is a reviewer, false otherwise
	 */
	public boolean checkReviewer(User user) {
		boolean result = false;
		for (int i = 0; i < reviewer.size(); i++) {
			if (user.getName().equals(reviewer.get(i).getName())) {
				result = true;
				break;
			}
		}
		return result;
	}
	
	public void addPaper(Paper newPap) {
		papers.add(newPap);
	}
	
	public List<Paper> getPapers() {
		return papers;
	}
	
	/**
	 * Returns if this user is an author
	 * @param user the user to be checked
	 * @return true if the user is an author, false otherwise
	 */
	public boolean checkAuthor(User user) {
		boolean result = false;
		for (int i = 0; i < author.size(); i++) {
			if (user.getName().equals(author.get(i).getName())) {
				result = true;
				break;
			}
		}
		return result;
	}

	/**
	 * Returns the name of the conference
	 */
	public String toString() {
		return confName;
	}

	/**
	 * Check to see if an object is equal to this conference object
	 * @return true if it is the same conference, false otherwise
	 */
	@Override
	public boolean equals(Object o) {
		Conference other_conference = (Conference) o;
		if (confID == other_conference.confID) {
			return true;
		} else {
			return false;
		}
	}
}
